export default {
	namespaced: true,
	state: {
		formData: {
			action: '',
			contactId: '',
			enterpriseId: '',
			enterpriseName: '',
			name: '',
			regMobile: '',
			contactLevel: '',
			sort: '',
			department: [],
			departmentIds: [],
			position: [],
			email: []
		}
	},
	mutations: {

		addReset (state, enterprise) {
			state.formData.action = 'add';
			state.formData.enterpriseId = enterprise.code;
			state.formData.enterpriseName = enterprise.name;
			state.formData.contactId = '';
			state.formData.name = '';
			state.formData.regMobile = '';
			state.formData.contactLevel = '100';
			state.formData.sort = '';
			state.formData.department = enterprise.department;
			state.formData.departmentIds = [];
			state.formData.position = [];
			state.formData.email = [];
			if (enterprise.department && enterprise.department[0]) {
				enterprise.department.forEach(v => {
					state.formData.departmentIds.push(v.departmentId);
				});
			}
		},

		editReset (state, data) {
			state.formData.action = 'update';
			state.formData.enterpriseId = data.enterpriseId;
			state.formData.enterpriseName = data.enterpriseName;
			state.formData.contactId = data.contactId;
			state.formData.name = data.name;
			state.formData.regMobile = data.mobile;
			state.formData.contactLevel = data.contactLevel;
			state.formData.sort = data.sort;
			state.formData.position = data.position ? data.position : [];
			state.formData.departmentId = data.departmentId;
			state.formData.departmentName = data.departmentName;
			// state.formData.department = data.department;
			// state.formData.email = data.email ? data.email : [];
			// data.department.forEach(v => {
			// 	state.formData.departmentIds.push(v.departmentId);
			// });
		},

		getDepartments (state, departments) {
			state.formData.department = departments;
			if (departments.length == 0) {
				return ;
			}
			departments.forEach(v => {
				state.formData.departmentIds.push(v.departmentId);
			});
		},

		setContactLevel (state, level) {
			state.formData.contactLevel = level;
		}
	}
}